package com.mkant.home.util;

import java.awt.Color;
import java.awt.Desktop;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.IOException;

import java.net.URI;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.Border;

public class Clock_AboutBoxPanel1 extends JPanel {
    private JLabel labelTitle = new JLabel();
    private JLabel labelAuthor = new JLabel();
    private JLabel labelCopyright = new JLabel();
    private JLabel labelCompany = new JLabel();
    private JLabel labelMoreInfo = new JLabel();
    private GridBagLayout layoutMain = new GridBagLayout();
    private Border border = BorderFactory.createEtchedBorder();
    private URI moreInfoURI;
    private JButton jButton1 = new JButton();
    private JLabel jLabel1 = new JLabel();
    private JLabel jLabel2 = new JLabel();

    public Clock_AboutBoxPanel1() {
        
        try {
            moreInfoURI = new URI("http://www.medicalbillingandcoding.org/sitting-kills");
            jbInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setLayout( layoutMain );
        this.setBorder( border );
        labelTitle.setText( "Stand up or Die Clock" );
        labelAuthor.setText( "Author: Mrityunjay Kant" );
//        labelCopyright.setText( "Copyright: LGPL-2.1" );
        labelCompany.setText( "Source License: LGPL-2.1" );
//        labelMoreInfo.setText("<HTML>Click the <FONT color=\"#000099\"><U>link</U></FONT> to go to the Java website.</HTML>");
        jButton1.setText("<HTML>Click the <FONT color=\"#000099\"><U>link</U></FONT> to get more info.</HTML>");
        jButton1.setHorizontalAlignment(SwingConstants.LEFT);
                jButton1.setBorderPainted(false);
                jButton1.setOpaque(false);
                jButton1.setBackground(Color.WHITE);
                jButton1.setToolTipText(moreInfoURI.toString());
                jButton1.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                                open(moreInfoURI);
                        }
                });


        jLabel1.setText("");
        jLabel2.setText("This program uses IntelliJ library for HotKeySupport.");
        jLabel2.setToolTipText("http://code.google.com/p/jintellitype/");
        this.add( labelTitle, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 15, 0, 15), 0, 0) );
        this.add( labelAuthor, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 15), 0, 0) );
//        this.add( labelCopyright, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 0, 15), 0, 0) );
        this.add( labelCompany, 
                 new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, 
                                        new Insets(0, 15, 5, 15), 0, 0));
//        this.add( labelMoreInfo, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 15, 5, 15), 0, 0) );
        this.add(jButton1, 
                 new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, 
                                        new Insets(0, 0, 0, 0), 0, 0));
        this.add(jLabel1, 
                 new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, 
                                        new Insets(0, 0, 0, 0), 0, 0));
        this.add(jLabel2, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, 
                    new Insets(0, 0, 0, 0), 0, 0));
    }
    
    private static void open(URI uri) {
            if (Desktop.isDesktopSupported()) {
                    Desktop desktop = Desktop.getDesktop();
                    try {
                            desktop.browse(uri);
                    } catch (IOException e) {
                            // TODO: error handling
                    }
            } else {
                    // TODO: error handling
            }
        }

}
